package cn.waqwb.controller;

import cn.waqwb.entity.Book;
import cn.waqwb.service.BookService;
import cn.waqwb.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author JokerQ
 * @date 2020/7/30 - 21:58
 */
public class BookListServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("BookList Post Run");
        /**
         * 1.获取书籍数据
         */
        /*BookService bookService = new BookServiceImpl();
        List<Book> bookList = bookService.getBooks();
        request.setAttribute("bookList",bookList);
        request.getRequestDispatcher("booklist.jsp").forward(request,response);*/
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("BookList Get Run");
        /**
         * 1.获取书籍数据
         */
        BookService bookService = new BookServiceImpl();
        List<Book> bookList = bookService.getBooks();
        req.setAttribute("bookList",bookList);
        req.getRequestDispatcher("booklist.jsp").forward(req,resp);
    }
}
